package bytesconv

import (
	"reflect"
	"unsafe"
)

func BytesToString(byte []byte) string {
	return *(*string)(unsafe.Pointer(&byte))
}

func StringToBytes(s string) []byte {
	return unsafe.Slice(unsafe.StringData(s), len(s))
}

func StringToBytesV2(s string) []byte {
	return *(*[]byte)(unsafe.Pointer(
		&struct {
			string
			Cap int
		}{s, len(s)},
	))
}
func StringToBytesV3(s string) []byte {
	sh := (*reflect.SliceHeader)(unsafe.Pointer(&s))
	bh := reflect.SliceHeader{
		Data: sh.Data,
		Len:  sh.Len,
		Cap:  sh.Cap,
	}
	return *(*[]byte)(unsafe.Pointer(&bh))
}
